package cn.woniu.ecommerceplatform.controller;

import cn.woniu.ecommerceplatform.entity.Goods;
import cn.woniu.ecommerceplatform.entity.Type;
import cn.woniu.ecommerceplatform.service.CommonService;
import cn.woniu.ecommerceplatform.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * @author NCQ
 * @date 2023/1/6
 * 图片或者文件上传或下载的接口
 */
@RestController
@RequestMapping("/common")
public class CommonController {
    /**
     * 文件上传
     * @return 标准返回信息
     */
    @Autowired
    private CommonService commonService;
    @PostMapping("/upload")
    @PreAuthorize("hasAnyAuthority('good:add','type:insert','good:update','type:update')")
    public ResponseResult<?> upload(MultipartFile file){
        return commonService.upload(file);
    }
    @GetMapping("/download")
    @PreAuthorize("hasAnyAuthority('good:query','type:query')")
    public void download(String name, HttpServletResponse response){
        commonService.download(name,response);
    }
    @PostMapping("/quit")
    @PreAuthorize("hasAnyAuthority('good:delete','good:update')")
    public ResponseResult<?> quit(@RequestBody Goods goods){
        return commonService.quit(goods);
    }
    @PostMapping("/quitType")
    @PreAuthorize("hasAnyAuthority('type:delete','type:update')")
    public ResponseResult<?> quitTypeImg(@RequestBody Type type){
        return commonService.quitType(type);
    }
}
